//
//  CYGDoubleTitleView.m
//  CYGHuntForCity
//
//  Created by cygarm on 16/3/5.
//  Copyright © 2016年 cygarm. All rights reserved.
//

#import "CYGDoubleTitleView.h"

@implementation CYGDoubleTitleView

- (instancetype)initWithFrame:(CGRect)frame {
	if (self = [super initWithFrame:frame]) {
		[self setupUI];
	}
	
	return self;
}

- (void)setupUI {
	self.title = [[UILabel alloc] init];
	self.subTitle = [[UILabel alloc] init];
	
	[self addTitleWith:self.title font:[UIFont boldSystemFontOfSize:16]];
	[self addTitleWith:self.subTitle font:[UIFont systemFontOfSize:13]];
	
	self.title.frame = CGRectMake(0, 0, self.bounds.size.width, 20);
	self.subTitle.frame = CGRectMake(0, 0, self.bounds.size.width, 20);
}

- (void)layoutSubviews {
	CGFloat centerX, centerY;
	
	centerX = self.bounds.size.width/2;
	centerY = self.bounds.size.height/2;
	if (_noStatusBar) {
		centerY += 10;
	}
	if (self.subTitle.text) {
		self.title.center = CGPointMake(centerX, centerY-10);
		self.subTitle.center = CGPointMake(centerX, centerY+10);
	} else {
		self.title.center = CGPointMake(centerX, centerY);
		[self.title setFont:[UIFont boldSystemFontOfSize:20]];
	}
}

- (void)addTitleWith:(UILabel *)label font:(UIFont *)font {
	label.textColor = [UIColor whiteColor];
	label.font = font;
	label.textAlignment = NSTextAlignmentCenter;
	[self addSubview:label];
}

@end
